package com.saris.primego.task;

import com.alibaba.fastjson2.JSON;
import com.saris.primego.websocket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class testTask {
    final WebSocketServer webSocketServer;

    public testTask(WebSocketServer webSocketServer) {
        this.webSocketServer = webSocketServer;
    }

//    @Scheduled(fixedRate = 300000)
    public void task() {
        log.info("开启定时任务:{}", LocalDateTime.now());
        //通过websocket向客户端浏览器推送消息 type orderId content
        Map<String, Object> map = new HashMap<>();
        map.put("type", 1); // 1表示来单提醒 2表示客户催单
        map.put("orderId", "000000");
        map.put("content", "订单号：" + 1111111);

        String json = JSON.toJSONString(map);
        webSocketServer.sendToAllClient(json);
    }
}
